#include <iostream>
#include <cstdio>
typedef long long ll;
ll sum[500005];
ll dp[500005];
using namespace std;
struct node {
    ll x;
    ll y;
};
node q[500005];
int st,en;
bool campare(node a, node b, node c) {
    return (b.y-a.y)*(c.x-b.x) < (c.y-b.y)*(b.x-a.x);
}
ll res(node a, int i) {
    return -2*sum[i]*a.x+a.y;
}
int main() {
    int n,m;
    ll tmp;
    node tmp1,tmp2;
    while (cin>>n>>m) {
        dp[0]=0;
        sum[0]=0;
        st=0,en=0;
        tmp1.x=0;
        tmp1.y=0;
        q[en]=tmp1; en++;
        q[en]=tmp1; en++;
        for (int i=1; i<=n; i++) {
            scanf("%lld", &tmp);
            sum[i]=sum[i-1]+tmp;
            tmp1.x=sum[i-1];
            tmp1.y=dp[i-1]+sum[i-1]*sum[i-1];
/*            cout<<"---"<<endl;
            for (int k=st; k<en; k++) cout<<q[k].x<<"--,--"<<q[k].y<<endl;
            cout<<"---"<<endl; */
            while (st+1<en && !campare(q[en-2],q[en-1],tmp1)) en--;
            q[en++]=tmp1;
            while (st+1<en && res(q[st+1], i)<=res(q[st], i)) st++;
            dp[i]=res(q[st],i)+m+sum[i]*sum[i];
        }
        cout<<dp[n]<<endl;
    }
    return 0;
}
